<?php

declare(strict_types=1);

namespace App\Model\CommodityModel;

use App\Model\BaseModel\BaseCommodityModel;
class CommodityOptimizationBbc extends BaseCommodityModel
{
    public $table = 'commodity_optimization_bbc';
    
    /**
     * 渠道商户ID
     * @param int $bid
     */
    public function getTableByBuID( int $bid = 0 )
    {
        $this->table = $bid > 0 ? 'commodity_optimization_bbc' : 'commodity_optimization_shop';
        return $this;
    }
    
    /**
     * 获取路由供应商商品
     * @param int $BuID
     * @param array $SkuCodes
     */
    public function getSkuIDListByBuIDAndSupplierSkuCodes( int $BuID , array $SkuCodes = [] )
    {
        return $this->getTableByBuID($BuID)
        ->select([
           "SkuID",
           "SupplierSKUCode AS SKUCode",
        ])
        ->where('BuID',$BuID)
        ->whereIn('SupplierSKUCode',$SkuCodes)
        ->where('IsInit',1)
        ->get()
        ->toArray();
    }

    /**
     * 根据用户ID和供应商商品sku获取优选池商品数据
     * @param  int $BuID
     * @param array $SupplierSkuCodes
     */
    public function getCopListByBuIDAndSupplierSkuCodes( int $BuID ,array $SupplierSkuCodes )
    {
        return $this->getTableByBuID($BuID)->where('BuID',$BuID)->whereIn('SupplierSKUCode',$SupplierSkuCodes)->get()->toArray();
    }

    /**
     * 根据用户ID和商品sku获取优选池商品数据
     * @param int $BuID
     * @param array $SkuCodes
     */
    public function getCopListByBuIDAndSkuCodes( int $BuID ,array $SkuCodes )
    {
        return $this->getTableByBuID($BuID)->where('BuID',$BuID)->whereIn('SKUCode',$SkuCodes)->get()->toArray();
    }
}
